package com.mes.schedule.manager;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.mes.basicdata.dao.RoutingDao;
import com.mes.basicdata.domain.Routing;
import com.mes.schedule.manager.iface.IScheduleRoutingManager;

@Component("scheduleRoutingManager")
@Transactional
public class ScheduleRoutingManager implements IScheduleRoutingManager{
	
	 
	public RoutingDao routingDao;

	/**
	 * 取得工艺分解时缺省的计划工艺 如果计划工艺没有，将取基础工艺中的路线
	 * 
	 * @param partUid
	 * @return
	 */
	public Routing getDefaultRouting(String partUid) {
		try {
			Routing planRouting = this.getDefaultPlanRouting(partUid);
			if (planRouting != null)
				return planRouting;

//			planRouting = (Routing) routingDao.getDefaultRouting(partUid);

			return planRouting;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return null;

	}

	 
	public Routing getDefaultPlanRouting(String partUid) {
		try {
			Routing planRouting = null;//routingDao.getDefaultPlanRouting(partUid);
			if (planRouting != null)
				return planRouting;

			List<Routing> routingList = null;//routingDao.getPlanRoutings(partUid, null);

			// 取最后一个工艺版本
			if (routingList != null && routingList.size() > 0)
				return routingList.get(routingList.size() - 1);
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return null;

	}
	
	 
	public void saveRouting(String scheduleUid, String partTaskUid,
			Routing destRouting) throws Exception {
//		if(destRouting.getRoutingManagerUid().equals(MMUtils.getSessionEmployeeId()))
//			routingManager.updateRouting(destRouting);
//		else
//		{
//			throw new Exception("权限不足，只能修改本人主管的工艺");
//		}
//			
//			List<Operation> opList=new ArrayList<Operation>();
//	
//			
//				
//			if(opTaskList!=null&&opTaskList.size()>0)
//			{
//
//
//				for(int i=0;i<opTaskList.size();i++)
//				{
//					SOperationTask operationTask=opTaskList.get(i);
//					Operation operation=new Operation();
//					operation.setUuid(String.valueOf(IdentityGenerator.GetIdentityLong()));
//					operation.setOperationId(Float.valueOf(i));
//					operation.setOperationIdDesc(operationTask.getOperationIdDesc());
//					operation.setRoutingUid(destRouting.getUuid());
//					operation.setEstiPreopTime(operationTask.getEstiPreTime());
//					operation.setEstiRunTime(operationTask.getEstiRunTime());
//					operation.setWorkCenterUid(operationTask.getDeviceClass());
//					opList.add(operation);
//				}
//				destRouting.setOperations(opList);
//			}
//			destRouting.setPartUid(partTask.getPartUid());
//
//			
//
	}

}
